<?php
require('./constrl/lookPage.php');
pdlook();
require('../model/conn.php');
// 处理新增板块表单提交
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["boardName"])) {
    $boardName = $_POST["boardName"];
    if ($boardName == "") {
        echo "<script>alert('板块名称不能为空');history.back();</script>";
        exit;
    }
    // 插入新板块
    $sql  = "INSERT INTO tbl_board (board_id, board_name) VALUES (NULL, '$boardName')";
    $rows = exec_update($sql);
    if ($rows > 0) {
        echo "<script>alert('板块添加成功');window.location.href='board_manage.php';</script>";
        exit;
    } else {
        echo "<script>alert('板块添加失败');window.location.href='board_manage.php';</script>";
        exit;
    }
}
// 查询所有板块
$boards = exec_select("SELECT board_id, board_name FROM tbl_board");
?>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>说点吧 - 板块管理</title>
  <link rel="stylesheet" href="../style/css/bootstrap.min.css">
  <link rel="stylesheet" href="../style/css/adminIndex.css">
  <link rel="stylesheet" href="../style/css/font-face.css">
</head>
<body>
  <!-- 导航栏 -->
  <nav class="navbar navbar-default">
    <div class="container-fluid">
      <div class="navbar-header">
        <span class="navbar-brand">说点吧 后台管理</span>
      </div>
      <ul class="nav navbar-nav">
        <li><a href="index.php">后台首页</a></li>
        <li><a href="user_manage.php">用户管理</a></li>
        <li><a href="user_upgrade.php">账户升级</a></li>
        <li class="active"><a href="board_manage.php">板块管理</a></li>
        <li><a href="article_manage.php">管理文章</a></li>
           <li>
          <?php
          if (isset($_SESSION['hdb']) && trim($_SESSION['hdb']) != '') {
            echo "<span> $_SESSION[hdb]</span><a href='view/adminOut.php'>退出管理</a>";
          }
          ?>
        </li>
      </ul>
    </div>
  </nav>

  <div class="container">
    <h2>文章板块管理</h2>
    <!-- 分类列表表格 -->
    <table class="table table-bordered">
      <thead>
        <tr>
          <th>板块ID</th>
          <th>板块名称</th>
        </tr>
      </thead>
      <tbody>
        <?php foreach ($boards as $board) { ?>
        <tr>
          <td><?php echo $board['board_id']; ?></td>
          <td><?php echo $board['board_name']; ?></td>
        </tr>
        <?php } ?>
      </tbody>
    </table>

    <hr>
    <h4>添加新板块</h4>
    <form method="post" class="form-inline">
      <div class="form-group">
        <label for="boardName">板块名称：</label>
        <input type="text" id="boardName" name="boardName" class="form-control" placeholder="输入新的板块名称">
      </div>
      <button type="submit" class="btn btn-primary">添加</button>
    </form>
  </div>

  <script src="../style/js/jquery.min.js"></script>
  <script src="../style/js/bootstrap.min.js"></script>
</body>
</html>
